--
-- PostgreSQL database dump
--

-- Started on 2012-06-04 21:32:33

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- TOC entry 333 (class 2612 OID 16386)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres
--

CREATE PROCEDURAL LANGUAGE plpgsql;


ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO postgres;

SET search_path = public, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 1534 (class 1259 OID 20803)
-- Dependencies: 6
-- Name: consulta; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE consulta (
    id integer NOT NULL,
    data date NOT NULL,
    hora time without time zone NOT NULL,
    tipo character varying(20),
    status character varying(20),
    obs character varying(500),
    pagamento double precision,
    profissional character varying(30) NOT NULL,
    paciente integer NOT NULL,
    convenio character varying(30),
    texto character varying(5000),
    anamnese character varying(5000)
);


ALTER TABLE public.consulta OWNER TO postgres;

--
-- TOC entry 1533 (class 1259 OID 20801)
-- Dependencies: 6 1534
-- Name: consulta_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE consulta_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.consulta_id_seq OWNER TO postgres;

--
-- TOC entry 1867 (class 0 OID 0)
-- Dependencies: 1533
-- Name: consulta_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE consulta_id_seq OWNED BY consulta.id;


--
-- TOC entry 1525 (class 1259 OID 20360)
-- Dependencies: 6
-- Name: convenio; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE convenio (
    nome character varying(50) NOT NULL,
    telefone1 character varying(30),
    telefone2 character varying(30),
    valor_cobrado double precision,
    email character varying(50),
    cnpj character varying(30)
);


ALTER TABLE public.convenio OWNER TO postgres;

--
-- TOC entry 1522 (class 1259 OID 20327)
-- Dependencies: 6
-- Name: funcionalidade; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE funcionalidade (
    id integer NOT NULL,
    nome character varying(100) NOT NULL
);


ALTER TABLE public.funcionalidade OWNER TO postgres;

--
-- TOC entry 1524 (class 1259 OID 20334)
-- Dependencies: 6
-- Name: paciente; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE paciente (
    id integer NOT NULL,
    nome character varying(100) NOT NULL,
    cpf character varying(20),
    rg character varying(20),
    cartao_sus character varying(20),
    prontuario character varying(20),
    nascimento date NOT NULL,
    status character varying(20) NOT NULL,
    sexo character varying(20) NOT NULL,
    mae character varying(50),
    pai character varying(50),
    estado_civil character varying(20) NOT NULL,
    cor character varying(30),
    email character varying(50),
    telefone1 character varying(30),
    telefone2 character varying(30),
    escolaridade character varying(50),
    logradouro character varying(50) NOT NULL,
    numero character varying(10) NOT NULL,
    bairro character varying(50),
    cep character varying(20),
    complemento character varying(50),
    cidade character varying(50) NOT NULL,
    estado character varying(50) NOT NULL
);


ALTER TABLE public.paciente OWNER TO postgres;

--
-- TOC entry 1523 (class 1259 OID 20332)
-- Dependencies: 6 1524
-- Name: paciente_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE paciente_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.paciente_id_seq OWNER TO postgres;

--
-- TOC entry 1868 (class 0 OID 0)
-- Dependencies: 1523
-- Name: paciente_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE paciente_id_seq OWNED BY paciente.id;


--
-- TOC entry 1520 (class 1259 OID 20317)
-- Dependencies: 6
-- Name: perfil; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE perfil (
    nome character varying(20) NOT NULL
);


ALTER TABLE public.perfil OWNER TO postgres;

--
-- TOC entry 1526 (class 1259 OID 20365)
-- Dependencies: 6
-- Name: perfil_funcionalidade; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE perfil_funcionalidade (
    perfil character varying(20) NOT NULL,
    funcionalidade integer NOT NULL,
    id integer NOT NULL
);


ALTER TABLE public.perfil_funcionalidade OWNER TO postgres;

--
-- TOC entry 1528 (class 1259 OID 20687)
-- Dependencies: 1526 6
-- Name: perfil_funcionalidade_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE perfil_funcionalidade_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.perfil_funcionalidade_id_seq OWNER TO postgres;

--
-- TOC entry 1869 (class 0 OID 0)
-- Dependencies: 1528
-- Name: perfil_funcionalidade_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE perfil_funcionalidade_id_seq OWNED BY perfil_funcionalidade.id;


--
-- TOC entry 1530 (class 1259 OID 20773)
-- Dependencies: 6
-- Name: profissional; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE profissional (
    cpf character varying(20) NOT NULL,
    registro character varying(30) NOT NULL,
    orgao_expedidor character varying(20),
    estado_expedidor character varying(20),
    rg character varying(30),
    categoria character varying(40) NOT NULL,
    especialidade character varying(30),
    nascimento date,
    telefone1 character varying(30),
    telefone2 character varying(30),
    email character varying(50),
    login character varying(20),
    sexo character varying(20),
    horario_trabalho character varying(50),
    valor_consulta money
);


ALTER TABLE public.profissional OWNER TO postgres;

--
-- TOC entry 1532 (class 1259 OID 20785)
-- Dependencies: 6
-- Name: profissional_convenio; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE profissional_convenio (
    id integer NOT NULL,
    profissional character varying(20),
    convenio character varying(50)
);


ALTER TABLE public.profissional_convenio OWNER TO postgres;

--
-- TOC entry 1531 (class 1259 OID 20783)
-- Dependencies: 1532 6
-- Name: profissional_convenio_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE profissional_convenio_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.profissional_convenio_id_seq OWNER TO postgres;

--
-- TOC entry 1870 (class 0 OID 0)
-- Dependencies: 1531
-- Name: profissional_convenio_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE profissional_convenio_id_seq OWNED BY profissional_convenio.id;


--
-- TOC entry 1536 (class 1259 OID 20831)
-- Dependencies: 6
-- Name: receita; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE receita (
    id integer NOT NULL,
    texto character varying(500) NOT NULL,
    registro character varying(20) NOT NULL,
    consulta integer NOT NULL
);


ALTER TABLE public.receita OWNER TO postgres;

--
-- TOC entry 1535 (class 1259 OID 20829)
-- Dependencies: 1536 6
-- Name: receita_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE receita_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.receita_id_seq OWNER TO postgres;

--
-- TOC entry 1871 (class 0 OID 0)
-- Dependencies: 1535
-- Name: receita_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE receita_id_seq OWNED BY receita.id;


--
-- TOC entry 1521 (class 1259 OID 20322)
-- Dependencies: 6
-- Name: usuario; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE usuario (
    login character varying(20) NOT NULL,
    senha character varying(20) NOT NULL,
    status character varying(20) NOT NULL,
    nome character varying(100)
);


ALTER TABLE public.usuario OWNER TO postgres;

--
-- TOC entry 1527 (class 1259 OID 20380)
-- Dependencies: 6
-- Name: usuario_perfil; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE usuario_perfil (
    usuario character varying(20) NOT NULL,
    perfil character varying(20) NOT NULL,
    id integer NOT NULL
);


ALTER TABLE public.usuario_perfil OWNER TO postgres;

--
-- TOC entry 1529 (class 1259 OID 20694)
-- Dependencies: 1527 6
-- Name: usuario_perfil_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE usuario_perfil_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MAXVALUE
    NO MINVALUE
    CACHE 1;


ALTER TABLE public.usuario_perfil_id_seq OWNER TO postgres;

--
-- TOC entry 1872 (class 0 OID 0)
-- Dependencies: 1529
-- Name: usuario_perfil_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE usuario_perfil_id_seq OWNED BY usuario_perfil.id;


--
-- TOC entry 1818 (class 2604 OID 20806)
-- Dependencies: 1533 1534 1534
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE consulta ALTER COLUMN id SET DEFAULT nextval('consulta_id_seq'::regclass);


--
-- TOC entry 1814 (class 2604 OID 20337)
-- Dependencies: 1524 1523 1524
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE paciente ALTER COLUMN id SET DEFAULT nextval('paciente_id_seq'::regclass);


--
-- TOC entry 1815 (class 2604 OID 20689)
-- Dependencies: 1528 1526
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE perfil_funcionalidade ALTER COLUMN id SET DEFAULT nextval('perfil_funcionalidade_id_seq'::regclass);


--
-- TOC entry 1817 (class 2604 OID 20788)
-- Dependencies: 1531 1532 1532
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE profissional_convenio ALTER COLUMN id SET DEFAULT nextval('profissional_convenio_id_seq'::regclass);


--
-- TOC entry 1819 (class 2604 OID 20834)
-- Dependencies: 1535 1536 1536
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE receita ALTER COLUMN id SET DEFAULT nextval('receita_id_seq'::regclass);


--
-- TOC entry 1816 (class 2604 OID 20696)
-- Dependencies: 1529 1527
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE usuario_perfil ALTER COLUMN id SET DEFAULT nextval('usuario_perfil_id_seq'::regclass);


--
-- TOC entry 1845 (class 2606 OID 20813)
-- Dependencies: 1534 1534
-- Name: consulta_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY consulta
    ADD CONSTRAINT consulta_id_key UNIQUE (id);


--
-- TOC entry 1847 (class 2606 OID 20811)
-- Dependencies: 1534 1534 1534 1534 1534 1534
-- Name: consulta_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY consulta
    ADD CONSTRAINT consulta_pkey PRIMARY KEY (id, data, hora, paciente, profissional);


--
-- TOC entry 1833 (class 2606 OID 20584)
-- Dependencies: 1525 1525
-- Name: convenio_cnpj_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY convenio
    ADD CONSTRAINT convenio_cnpj_key UNIQUE (cnpj);


--
-- TOC entry 1835 (class 2606 OID 20364)
-- Dependencies: 1525 1525
-- Name: convenio_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY convenio
    ADD CONSTRAINT convenio_pkey PRIMARY KEY (nome);


--
-- TOC entry 1825 (class 2606 OID 20331)
-- Dependencies: 1522 1522
-- Name: funcionalidade_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY funcionalidade
    ADD CONSTRAINT funcionalidade_pkey PRIMARY KEY (id);


--
-- TOC entry 1827 (class 2606 OID 20344)
-- Dependencies: 1524 1524
-- Name: paciente_cpf_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY paciente
    ADD CONSTRAINT paciente_cpf_key UNIQUE (cpf);


--
-- TOC entry 1829 (class 2606 OID 20342)
-- Dependencies: 1524 1524
-- Name: paciente_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY paciente
    ADD CONSTRAINT paciente_pkey PRIMARY KEY (id);


--
-- TOC entry 1831 (class 2606 OID 20346)
-- Dependencies: 1524 1524
-- Name: paciente_rg_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY paciente
    ADD CONSTRAINT paciente_rg_key UNIQUE (rg);


--
-- TOC entry 1837 (class 2606 OID 20369)
-- Dependencies: 1526 1526 1526
-- Name: perfil_funcionalidade_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY perfil_funcionalidade
    ADD CONSTRAINT perfil_funcionalidade_pkey PRIMARY KEY (perfil, funcionalidade);


--
-- TOC entry 1821 (class 2606 OID 20321)
-- Dependencies: 1520 1520
-- Name: perfil_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY perfil
    ADD CONSTRAINT perfil_pkey PRIMARY KEY (nome);


--
-- TOC entry 1843 (class 2606 OID 20790)
-- Dependencies: 1532 1532
-- Name: profissional_convenio_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY profissional_convenio
    ADD CONSTRAINT profissional_convenio_pkey PRIMARY KEY (id);


--
-- TOC entry 1841 (class 2606 OID 20777)
-- Dependencies: 1530 1530
-- Name: profissional_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY profissional
    ADD CONSTRAINT profissional_pkey PRIMARY KEY (cpf);


--
-- TOC entry 1849 (class 2606 OID 20839)
-- Dependencies: 1536 1536
-- Name: receita_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY receita
    ADD CONSTRAINT receita_pkey PRIMARY KEY (id);


--
-- TOC entry 1839 (class 2606 OID 20384)
-- Dependencies: 1527 1527 1527
-- Name: usuario_perfil_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY usuario_perfil
    ADD CONSTRAINT usuario_perfil_pkey PRIMARY KEY (usuario, perfil);


--
-- TOC entry 1823 (class 2606 OID 20326)
-- Dependencies: 1521 1521
-- Name: usuario_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT usuario_pkey PRIMARY KEY (login);


--
-- TOC entry 1857 (class 2606 OID 20814)
-- Dependencies: 1832 1525 1534
-- Name: consulta_convenio_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY consulta
    ADD CONSTRAINT consulta_convenio_fkey FOREIGN KEY (convenio) REFERENCES convenio(cnpj);


--
-- TOC entry 1858 (class 2606 OID 20819)
-- Dependencies: 1524 1828 1534
-- Name: consulta_paciente_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY consulta
    ADD CONSTRAINT consulta_paciente_fkey FOREIGN KEY (paciente) REFERENCES paciente(id);


--
-- TOC entry 1859 (class 2606 OID 20824)
-- Dependencies: 1534 1530 1840
-- Name: consulta_profissional_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY consulta
    ADD CONSTRAINT consulta_profissional_fkey FOREIGN KEY (profissional) REFERENCES profissional(cpf);


--
-- TOC entry 1851 (class 2606 OID 20375)
-- Dependencies: 1824 1526 1522
-- Name: perfil_funcionalidade_funcionalidade_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY perfil_funcionalidade
    ADD CONSTRAINT perfil_funcionalidade_funcionalidade_fkey FOREIGN KEY (funcionalidade) REFERENCES funcionalidade(id);


--
-- TOC entry 1850 (class 2606 OID 20370)
-- Dependencies: 1520 1526 1820
-- Name: perfil_funcionalidade_perfil_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY perfil_funcionalidade
    ADD CONSTRAINT perfil_funcionalidade_perfil_fkey FOREIGN KEY (perfil) REFERENCES perfil(nome);


--
-- TOC entry 1855 (class 2606 OID 20791)
-- Dependencies: 1532 1525 1834
-- Name: profissional_convenio_convenio_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY profissional_convenio
    ADD CONSTRAINT profissional_convenio_convenio_fkey FOREIGN KEY (convenio) REFERENCES convenio(nome);


--
-- TOC entry 1856 (class 2606 OID 20796)
-- Dependencies: 1530 1840 1532
-- Name: profissional_convenio_profissional_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY profissional_convenio
    ADD CONSTRAINT profissional_convenio_profissional_fkey FOREIGN KEY (profissional) REFERENCES profissional(cpf);


--
-- TOC entry 1854 (class 2606 OID 20778)
-- Dependencies: 1530 1521 1822
-- Name: profissional_login_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY profissional
    ADD CONSTRAINT profissional_login_fkey FOREIGN KEY (login) REFERENCES usuario(login);


--
-- TOC entry 1860 (class 2606 OID 20840)
-- Dependencies: 1844 1536 1534
-- Name: receita_consulta_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY receita
    ADD CONSTRAINT receita_consulta_fkey FOREIGN KEY (consulta) REFERENCES consulta(id);


--
-- TOC entry 1861 (class 2606 OID 20845)
-- Dependencies: 1530 1840 1536
-- Name: receita_registro_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY receita
    ADD CONSTRAINT receita_registro_fkey FOREIGN KEY (registro) REFERENCES profissional(cpf);


--
-- TOC entry 1853 (class 2606 OID 20390)
-- Dependencies: 1820 1520 1527
-- Name: usuario_perfil_perfil_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY usuario_perfil
    ADD CONSTRAINT usuario_perfil_perfil_fkey FOREIGN KEY (perfil) REFERENCES perfil(nome);


--
-- TOC entry 1852 (class 2606 OID 20385)
-- Dependencies: 1521 1527 1822
-- Name: usuario_perfil_usuario_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY usuario_perfil
    ADD CONSTRAINT usuario_perfil_usuario_fkey FOREIGN KEY (usuario) REFERENCES usuario(login);


--
-- TOC entry 1866 (class 0 OID 0)
-- Dependencies: 6
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


-- Completed on 2012-06-04 21:32:34

--
-- PostgreSQL database dump complete
--

